package com.qf.homwork.model;

import org.junit.Test;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Queue;

public class IOReaderFile {

    private BufferedReader bufferedReader;

    public IOReaderFile() {
    }

    public IOReaderFile(BufferedReader bufferedReader) {
        this.bufferedReader = bufferedReader;
    }

    public BufferedReader getBufferedReader() {
        return bufferedReader;
    }

    public  void setBufferedReader(BufferedReader bufferedReader) {
        this.bufferedReader = bufferedReader;
    }



    //文件读入
    public HashMap readFileIO() throws IOException {
        HashMap<Integer, String> map = new HashMap<>();
        bufferedReader = new BufferedReader(new FileReader("D:\\names.txt"));

        int i = 0;
        while (true) {
            String s = bufferedReader.readLine();
            if (s == null) {
                break;
            }
            if (s != null) {
                map.put(i,s);
                i++;
//                System.out.println(s);
            }

        }

        bufferedReader.close();
        return map;
    }


    public static void main(String[] args) throws IOException {
        HashMap map = new IOReaderFile().readFileIO();//得到map集合
        for (Object o : map.entrySet()) {
            System.out.println(o);

        }

    }

}
